package com.CGFrame.tools;

import java.io.File;
import java.util.ArrayList;

import java.util.Collections;
import java.util.Iterator;

import com.CGFrame.struts.bean.unit.ShotBean;

public class FileFilter {
	
	public static ArrayList getFiles(String path ,String name)
	{
		try
		{
			ArrayList<String> results = new ArrayList<String>()  ;
			File file = new File(path);
			if(! file.canRead())
			{
				System.out.println(path+":  path error");
				return null;
			}
			File[] list = file.listFiles();
			for (int i = 0; i < list.length; i++)
    		{
    			if (list[i].isDirectory())
    			{
    				continue;
    			}
    				//搜索
    			String currentFile = list[i].getName();
    			String output = currentFile.toLowerCase();
    			name = name.toLowerCase();
    			if ( output.startsWith(name) )
    			{
    				results.add(currentFile);
    			}
    		}
			Collections.sort(results);  
			
			return results;
		}
		catch (Exception e)
		{

    		System.out.println(path+" "+"拒绝访问");
    		return null;
		}
	}
	
	public static void main(String[] args)
	{
		ShotBean shotBean = new ShotBean(282);
		System.out.println(shotBean.getStoryBoardPath());
		System.out.println(shotBean.getShotName());
		ArrayList results = getFiles(shotBean.getStoryBoardPath(),shotBean.getShotName());
		Iterator ite = results.iterator();
		while (ite.hasNext())
		{
			System.out.println((String)ite.next());
		}
		
	}

	public static boolean isRealPath(String path) {
		File file = new File(path);
		if(! file.canRead())
		{
			System.out.println(path+":  path error");
			return false;
		}
		return true;
	}
	public static boolean makeFilePath(String path){
		File file = new File(path);
		if (file.canRead())
		{
			return true;
		}
		else
		{
			return file.mkdirs();
		}
	}
}